package com.loveyukari.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

@Configuration
@EnableAsync
public class ExecutorConfig {
    @Autowired
    private Environment env;


    @Bean
    public ThreadPoolTaskExecutor executor(){
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(env.getProperty("yukari.executor.core-pool-size",Integer.class,10));
        executor.setMaxPoolSize(env.getProperty("yukari.executor.max-pool-size",Integer.class,100));
        executor.setKeepAliveSeconds(env.getProperty("yukari.executor.keep-alive-seconds",Integer.class,120));
        executor.setQueueCapacity(env.getProperty("yukari.executor.queue-capacity",Integer.class,0));
        executor.setThreadNamePrefix("douyu196-executor-");
        return executor;
    }


}
